//
//  ZH_OrderCollectionViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/19.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_OrderCollectionViewCell.h"
@interface ZH_OrderCollectionViewCell()
///图标
@property (nonatomic, weak) UIImageView *iconImageView;
///标题
@property (nonatomic, weak) UILabel *titleLabel;
@end
@implementation ZH_OrderCollectionViewCell
///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[ZH_OrderCollectionViewCell class] forCellWithReuseIdentifier:@"ZH_OrderCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"ZH_OrderCollectionViewCell" forIndexPath:indexPath];
}
///更新 ui
- (void)updateUiForIcon:(NSString *)icon andTitle:(NSString *)title
{
    [self.iconImageView setImageForName:icon];
    self.titleLabel.text = title;
}
///加载子视图约束
-(void)loadSubviewConstraints
{
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(15));
        make.centerX.equalTo(self.contentView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.iconImageView.mas_bottom).offset(FITSCALE(10));
    }];
}
#pragma mark - getter,setter
- (UIImageView *)iconImageView
{
    if(!_iconImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        //        image.backgroundColor = [UIColor redColor];
        image.contentMode = UIViewContentModeScaleToFill;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_iconImageView = image];
    }
    return _iconImageView;
}


- (UILabel *)titleLabel
{
    if(!_titleLabel){
        UILabel *label = [UILabel createLabelWithText:@"" font:kFontSize_28];
        label.textColor = [UIColor colorWithHexString:@"#5C5C5C"];
        [label setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
@end
